package com.haibara.codesandbox.controller;

import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: mengyu
 * @Date: 2025/5/3
 */
@Service
public class Dashboard {
    private AtomicInteger totalCount;
    private LocalDate date;

    public Dashboard() {
        totalCount = new AtomicInteger(0);
        date = LocalDate.now();
    }

    public void count() {
        if (!LocalDate.now().isEqual(date)) {
            totalCount = new AtomicInteger(0);
            date = LocalDate.now();
        }
        totalCount.incrementAndGet();
    }

    public String getTotalInfo() {
        return String.format(
                "当前日期为:%s%n今日运行代码请求数:%d",
                date.format(DateTimeFormatter.ISO_DATE),  // 格式化为 "YYYY-MM-DD"
                totalCount.get()
        );
    }

}
